/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package xmlobject;

import com.sun.codemodel.JCodeModel;
import com.sun.tools.xjc.api.ErrorListener;
import com.sun.tools.xjc.api.S2JJAXBModel;
import com.sun.tools.xjc.api.SchemaCompiler;
import com.sun.tools.xjc.api.XJC;
import java.io.File;
import java.io.IOException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;

/**
 *
 * @author tiz
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String output = "src/";
        String source = "src/xsd/Rate.xsd";
        GenObject(output,source);
    }

    public static void GenObject(String output, String source)
    {
        try
        {
            SchemaCompiler sc = XJC.createSchemaCompiler();
            sc.setErrorListener(new ErrorListener() {

                public void error(SAXParseException saxpe) {
                    saxpe.printStackTrace();
                }

                public void fatalError(SAXParseException saxpe) {
                    saxpe.printStackTrace();
                }

                public void warning(SAXParseException saxpe) {
                    saxpe.printStackTrace();
                }

                public void info(SAXParseException saxpe) {
                    saxpe.printStackTrace();
                }
            });

            sc.forcePackageName("entity");
            File schema = new File(source);
            InputSource is = new InputSource(schema.toURI().toString());
            sc.parseSchema(is);
            S2JJAXBModel model = sc.bind();
            JCodeModel code = model.generateCode(null, null);
            code.build(new File(output));
            System.out.println("Done!");

        }catch(IOException e)
        {
            e.printStackTrace();
        }
    }

}
